package ty.tryagainforever1129.pikachumemory.adaper;
import java.util.ArrayList;
import ty.tryagainforever1129.pikachumemory.R;
import ty.tryagainforever1129.pikachumemory.model.UserModel;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LeaderBoardAdapter extends BaseAdapter {
    private ArrayList<UserModel> listData;
    private LayoutInflater inflater;

    public LeaderBoardAdapter(Context mcontext, ArrayList<UserModel> mlistData) {
        this.listData = mlistData;
        inflater = LayoutInflater.from(mcontext);
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HolderView holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.leader_boards_row_layout, null);
            // init view.
            holder = new HolderView();
            holder.setUserName((TextView) convertView.findViewById(R.id.user_name));
            holder.setScore((TextView) convertView.findViewById(R.id.score));
            // set tag.
            convertView.setTag(holder);
        } else {
            holder = (HolderView) convertView.getTag();
        }
        // init data.
        holder.getUserName().setText(listData.get(position).getUserName());
        holder.getScore().setText(String.valueOf(listData.get(position).getScrore()));
        return convertView;
    }

    public class HolderView {
        private TextView userName;
        private TextView score;

        public TextView getScore() {
            return score;
        }

        public void setScore(TextView score) {
            this.score = score;
        }

        public TextView getUserName() {
            return userName;
        }

        public void setUserName(TextView userName) {
            this.userName = userName;
        }
    }
}
